<?php

    $link = mysqli_connect("localhost","root","") or die("数据连接失败");
    mysqli_set_charset($link,"utf8");
    mysqli_select_db($link,"bbs");

    switch($_GET['a']){

        case 'del':
            $id = $_GET['id'];
            $sql = "delete from post where id={$id}";
            $result = mysqli_query($link,$sql);

            if($result && mysqli_affected_rows($link)>0){
                echo "<script>alert('删除成功！');window.location.href='./main_list.php';</script>";
                die;
            }else{
                echo "<script>alert('删除失败！');window.location.href='./main_list.php';</script>";
                die;
            }

            break;
        case 'return':
            $id = $_GET['id'];
            $sql = "update post set recycle='1' where id={$id}";
            mysqli_query($link,$sql);
            if(mysqli_affected_rows($link)>0){
                echo "<script>alert('放入回车站成功！');window.location.href='./return.php';</script>";
                die;
            }else{
                echo "<script>alert('放入回车站失败！');window.location.href='./main_list.php';</script>";
                die;
            }
            break;
        case 'recover':
            $id = $_GET['id'];
            $sql = "update post set recycle='0' where id={$id}";
            mysqli_query($link,$sql);
            if(mysqli_affected_rows($link)>0){
                echo "<script>alert('恢复成功！');window.location.href='./main_list.php';</script>";
                die;
            }else{
                echo "<script>alert('恢复失败！');window.location.href='./return.php';</script>";
                die;
            }
            break;
        case 'elite':
            $id = $_GET['id'];
            $elite = $_GET['elite'];
//            var_dump($elite);
            if($elite==0){
                $sql = "update post set elite='1' where id={$id}";
                mysqli_query($link,$sql);
                if(mysqli_affected_rows($link)>0){
                    echo "<script>alert('加精成功！');window.location.href='./main_list.php';</script>";
                    die;
                }else{
                    echo "<script>alert('加精失败！');window.location.href='.//main_list.php';</script>";
                    die;
                }
            }else{
                $sql = "update post set elite='0' where id={$id}";
                mysqli_query($link,$sql);
                if(mysqli_affected_rows($link)>0){
                    echo "<script>alert('取消加精成功！');window.location.href='./main_list.php';</script>";
                    die;
                }else{
                    echo "<script>alert('取消加精失败！');window.location.href='.//main_list.php';</script>";
                    die;
                }
            }
            break;
        case 'top':
            $id = $_GET['id'];
            $top = $_GET['top'];
//            var_dump($top);
            if($top==0){
                $sql = "update post set top='1' where id={$id}";
                mysqli_query($link,$sql);
                if(mysqli_affected_rows($link)>0){
                    echo "<script>alert('置顶成功！');window.location.href='./main_list.php';</script>";
                    die;
                }else{
                    echo "<script>alert('置顶失败！');window.location.href='.//main_list.php';</script>";
                    die;
                }
            }else{
                $sql = "update post set top='0' where id={$id}";
                mysqli_query($link,$sql);
                if(mysqli_affected_rows($link)>0){
                    echo "<script>alert('取消置顶成功！');window.location.href='./main_list.php';</script>";
                    die;
                }else{
                    echo "<script>alert('取消置顶失败！');window.location.href='.//main_list.php';</script>";
                    die;
                }
            }
            break;
        case 'delreply':

            $link = mysqli_connect("localhost","root","") or die("数据连接失败");
            mysqli_set_charset($link,"utf8");
            mysqli_select_db($link,"bbs");
            $pid = $_GET['pid'];
            $id = $_GET['id'];
            $sql = "delete from reply where id={$pid}";
            $result = mysqli_query($link,$sql);

            if($result && mysqli_affected_rows($link)>0){
                echo "<script>alert('删除成功！');window.location.href='./checkreply.php?id={$id}';</script>";
                die;
            }else{
                echo "<script>alert('删除失败！');window.location.href='./checkreply.php?id={$id}';</script>";
                die;
            }
            mysqli_close($link);
            break;

    }
    mysqli_close($link);